package com.lscl.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer02_WorkQueues {

    public static void main(String[] args) throws Exception {
        // 创建连接工厂,用于获取频道channel
        ConnectionFactory factory = new ConnectionFactory();

        factory.setHost("192.168.40.132");
        factory.setPort(5672);
        factory.setUsername("lscl");
        factory.setPassword("admin");
        factory.setVirtualHost("/lscl");

        // 2.创建连接
        Connection connection = factory.newConnection();

        // 3.创建频道
        Channel channel = connection.createChannel();

        // 4.创建队列
        channel.queueDeclare("work_queues", true, false, false, null);

        //5. 循环发送10条消息到work_queues队列
        for (int i = 1; i <= 10; i++) {
            String body = "hello" + i;
            channel.basicPublish("", "work_queues", null, body.getBytes());
        }

        //6.释放资源
        channel.close();
        connection.close();
    }
}
